//document.write("<script language=javascript src='param.js'></script>");
Blockly.Blocks['block_inittime'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("Start at:")
            .appendField(new Blockly.FieldTextInput("00:00", function(newValue) {
                var reg = RegExp("^[0-5]{0,1}[0-9]{1,1}:[0-5]{1,1}[0-9]{1,1}$");
                if (!reg.test(newValue)) {
                    if(newValue.indexOf(":")!=-1)
                    {
                        var minute=newValue.substr(0,newValue.indexOf(":"));
                        var second=newValue.substr(newValue.indexOf(":")+1);
                        var imin=parseInt(minute);
                        var isec=parseInt(second);
                        if(isec>60)
                        {
                            imin+=Math.floor(isec/60);
                            isec=isec%60;
                        } 
                        var smin=imin.toFixed(0).toString();
                        var ssec=isec.toFixed(0).toString();
                        var len = smin.length;
                        if(len<2)
                        {
                            smin='0'+smin;
                        }
                        len=ssec.length;
                        if(len<2)
                        {
                            ssec='0'+ssec;
                        }
                        newValue = smin+':'+ssec;
                    }
                    
                }
                return newValue;

            }), "time")
            .appendField(new Blockly.FieldColour("#cccccc"), "color");
        this.appendStatementInput("functionIntit")
            .setCheck(null);
        this.setPreviousStatement(true, "time");
        this.setNextStatement(true, "time");
        this.setColour(310);
        this.setTooltip('');
    }
};
Blockly.Python['block_inittime'] = function(block) {
    var text_time = block.getFieldValue('time');
    var colour_color = block.getFieldValue('color');
    var statements_functionintit = Blockly.Python.statementToCode(block, 'functionIntit');
    // TODO: Assemble Python into code variable.
    var code = 'inittime(' + text_time + ')' + '\n' + statements_functionintit;
    return code;
};

Blockly.Blocks['Goertek_Point'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("标定点 ")
            .appendField("名称")
            .appendField(new Blockly.FieldTextInput("a"), "name")
            .appendField(" X")
            .appendField(new Blockly.FieldNumber(0, 0, getLength()), "X")
            .appendField("cm")
            .appendField("Y")
            .appendField(new Blockly.FieldNumber(0, 0, getWidth()), "Y")
            .appendField("cm")
            .appendField("Z")
            .appendField(new Blockly.FieldNumber(80, 80, getHeight()), "Z")
            .appendField("cm");
        this.setInputsInline(true);
        this.setPreviousStatement(true, ["action", "notReachAction", "ReachAction"]);
        this.setNextStatement(true, ["action", "notReachAction", "ReachAction"]);
        this.setColour(250);
        this.setTooltip('');
    }
};
Blockly.Python['Goertek_Point'] = function(block) {
    var name = block.getFieldValue('name');
    var px = block.getFieldValue('X');
    var py = block.getFieldValue('Y');
    var pz = block.getFieldValue('Z');
    // TODO: Assemble Python into code variable.
    var code = 'AddMark(\'' + name + '\',' + px + ',' + py + ',' + pz + ')' + '\n';
    //var code = '';
    return code;
};

Blockly.Blocks['block_delay'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("延时")
            .appendField(new Blockly.FieldDropdown([
                ["ms", "0"],
                ["s", "1"],
                ["min", "2"]
            ]), "delay")
            .appendField(new Blockly.FieldTextInput("1000"), "time");
        this.setPreviousStatement(true, ["action", "notReachAction", "ReachAction"]);
        this.setNextStatement(true, ["action", "notReachAction", "ReachAction"]);
        this.setColour(160);
        this.setTooltip('');
    }
};
Blockly.Python['block_delay'] = function(block) {
    var dropdown_delay = block.getFieldValue('delay');
    var dropdown_time = block.getFieldValue('time');
    // TODO: Assemble Python into code variable.
    if (dropdown_delay == 0)
        var code = 'Delay(' + dropdown_time + ')' + '\n';
    else if (dropdown_delay == 1)
        var code = 'Delay(' + dropdown_time * 1000 + ')' + '\n';
    else if (dropdown_delay == 2)
        var code = 'Delay(' + dropdown_time * 60000 + ')' + '\n';

    return code;
};

Blockly.Blocks['Goertek_HorizontalSpeed'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("水平速度 ")
            .appendField(new Blockly.FieldNumber(60, 20, 200), "VH")
            .appendField("cm/s")
            .appendField("水平加速度 ")
            .appendField(new Blockly.FieldNumber(100, 50, 400), "AH")
            .appendField("cm/s²")
        this.setInputsInline(true);
        this.setPreviousStatement(true, ["action", "notReachAction", "ReachAction"]);
        this.setNextStatement(true, ["action", "notReachAction", "ReachAction"]);
        this.setColour(250);
        this.setTooltip('');
    }
};
Blockly.Python['Goertek_HorizontalSpeed'] = function(block) {
    var hspeed = block.getFieldValue('VH');
     var ha = block.getFieldValue('AH');
    // TODO: Assemble Python into code variable.
    var code = 'MaxVelXY(f1,' + hspeed + ')' + '\n'+'MaxAccXY(f1,' + ha + ')' + '\n';
    //var code = '';
    return code;
};

Blockly.Blocks['Goertek_HorizontalAcceleration'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("水平加速度 ")
            .appendField(new Blockly.FieldNumber(100, 50, 400), "AH")
            .appendField("cm/s²")
        this.setInputsInline(true);
        this.setPreviousStatement(true, ["action", "notReachAction", "ReachAction"]);
        this.setNextStatement(true, ["action", "notReachAction", "ReachAction"]);
        this.setColour(250);
        this.setTooltip('');
    }
};
Blockly.Python['Goertek_HorizontalAcceleration'] = function(block) {
    var ha = block.getFieldValue('AH');
    // TODO: Assemble Python into code variable.
    var code = 'MaxAccXY(f1,' + ha + ')' + '\n';
    //var code = '';
    return code;
};

Blockly.Blocks['Goertek_VerticalSpeed'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("垂直速度 ")
            .appendField(new Blockly.FieldNumber(100, 60, 200), "VV")
            .appendField("cm/s")
            .appendField("垂直加速度 ")
            .appendField(new Blockly.FieldNumber(200, 50, 400), "AV")
            .appendField("cm/s²")
        this.setInputsInline(true);
        this.setPreviousStatement(true, ["action", "notReachAction", "ReachAction"]);
        this.setNextStatement(true, ["action", "notReachAction", "ReachAction"]);
        this.setColour(250);
        this.setTooltip('');
    }
};
Blockly.Python['Goertek_VerticalSpeed'] = function(block) {
    var hspeed = block.getFieldValue('VV');
     var ha = block.getFieldValue('AV');
    // TODO: Assemble Python into code variable.
    var code = 'MaxVelZ(f1,' + hspeed + ')' + '\n'+'MaxAccZ(f1,' + ha + ')' + '\n';
    //var code = '';
    return code;
};

Blockly.Blocks['Goertek_VerticalAcceleration'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("垂直加速度 ")
            .appendField(new Blockly.FieldNumber(200, 50, 400), "AV")
            .appendField("cm/s²")
        this.setInputsInline(true);
        this.setPreviousStatement(true, ["action", "notReachAction", "ReachAction"]);
        this.setNextStatement(true, ["action", "notReachAction", "ReachAction"]);
        this.setColour(250);
        this.setTooltip('');
    }
};
Blockly.Python['Goertek_VerticalAcceleration'] = function(block) {
    var ha = block.getFieldValue('AV');
    // TODO: Assemble Python into code variable.
    var code = 'MaxAccZ(f1,' + ha + ')' + '\n';
    //var code = '';
    return code;
};

Blockly.Blocks['Goertek_AngularVelocity'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("角速度 ")
            .appendField(new Blockly.FieldNumber(60, 5, 120), "w")
            .appendField("°/s")
        this.setInputsInline(true);
        this.setPreviousStatement(true, ["action", "notReachAction", "ReachAction"]);
        this.setNextStatement(true, ["action", "notReachAction", "ReachAction"]);
        this.setColour(250);
        this.setTooltip('');
    }
};
Blockly.Python['Goertek_AngularVelocity'] = function(block) {
    var w = block.getFieldValue('w');
    // TODO: Assemble Python into code variable.
    var code = 'MaxAngularRate(f1,' + w + ')' + '\n';
    //var code = '';
    return code;
};

Blockly.Blocks['Goertek_TurnTo'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("转向")
            .appendField(new Blockly.FieldDropdown([
                ["左", "l"],
                ["右", "r"]
            ]), "turnDirection")
            .appendField(new Blockly.FieldNumber(0, 0, 359), "angle")
            .appendField("°");
        this.setPreviousStatement(true, "notReachAction");
        this.setNextStatement(true, "notReachAction");
        this.setColour(160);
        this.setTooltip('');
    }
};
Blockly.Python['Goertek_TurnTo'] = function(block) {
    var turnDirection = block.getFieldValue('turnDirection');
    var angle = block.getFieldValue('angle');
    // TODO: Assemble Python into code variable.
    var code = 'Yaw2(f1,\'' + turnDirection + '\',' + angle + ')' + '\n';
    return code;
};

Blockly.Blocks['Goertek_Turn'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("转动")
            .appendField(new Blockly.FieldDropdown([
                ["左", "l"],
                ["右", "r"]
            ]), "turnDirection")
            .appendField(new Blockly.FieldNumber(0, 0, 360), "angle")
            .appendField("°");
        this.setPreviousStatement(true, "notReachAction");
        this.setNextStatement(true, "notReachAction");
        this.setColour(160);
        this.setTooltip('');
    }
};
Blockly.Python['Goertek_Turn'] = function(block) {
    var turnDirection = block.getFieldValue('turnDirection');
    var angle = block.getFieldValue('angle');
    // TODO: Assemble Python into code variable.
    var code = 'Yaw(f1,\'' + turnDirection + '\',' + angle + ')' + '\n';
    return code;
};

Blockly.Blocks['Goertek_MoveToCoord'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("直线移至 ")
            .appendField("X")
            .appendField(new Blockly.FieldNumber(0, 0, getLength()), "X")
            .appendField("cm")
            .appendField("Y")
            .appendField(new Blockly.FieldNumber(0, 0, getWidth()), "Y")
            .appendField("cm")
            .appendField("Z")
            .appendField(new Blockly.FieldNumber(80, 80, getHeight()), "Z")
            .appendField("cm");
        this.setInputsInline(true);
        this.setPreviousStatement(true, "notReachAction");
        this.setNextStatement(true, "notReachAction");
        this.setColour(250);
        this.setTooltip('');
    }
};
Blockly.Python['Goertek_MoveToCoord'] = function(block) {
    var px = block.getFieldValue('X');
    var py = block.getFieldValue('Y');
    var pz = block.getFieldValue('Z');
    // TODO: Assemble Python into code variable.
    var code = 'Move2(f1,' + px + ',' + py + ',' + pz + ')' + '\n';
    //var code = '';
    return code;
};

Blockly.Blocks['Goertek_MoveToPoint'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("直线移至 ")
            .appendField("标定点")
            .appendField(new Blockly.FieldTextInput("a"), "point");
        this.setInputsInline(true);
        this.setPreviousStatement(true, "notReachAction");
        this.setNextStatement(true, "notReachAction");
        this.setColour(250);
        this.setTooltip('');
    }
};
Blockly.Python['Goertek_MoveToPoint'] = function(block) {
    var point = block.getFieldValue('point');
    var code = 'Move2Marker(f1,\'' + point + '\')' + '\n';
    return code;
};

Blockly.Blocks['Goertek_Move'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("X方向移动")
            .appendField(new Blockly.FieldNumber(0, -getLength(), getLength()), "X")
            .appendField("cm")
            .appendField("Y方向移动")
            .appendField(new Blockly.FieldNumber(0, -getWidth(), getWidth()), "Y")
            .appendField("cm")
            .appendField("Z方向移动")
            .appendField(new Blockly.FieldNumber(0, -getHeight(), getHeight()), "Z")
            .appendField("cm");
        this.setInputsInline(true);
        this.setPreviousStatement(true, "notReachAction");
        this.setNextStatement(true, "notReachAction");
        this.setColour(250);
        this.setTooltip('');
    }
};
Blockly.Python['Goertek_Move'] = function(block) {
    var px = block.getFieldValue('X');
    var py = block.getFieldValue('Y');
    var pz = block.getFieldValue('Z');
    // TODO: Assemble Python into code variable.
    var code = 'MoveDelta(f1,' + px + ',' + py + ',' + pz + ')' + '\n';
    // var code = '';
    return code;
};
Blockly.Blocks['Goertek_ReachPosition'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("Reach直线移至 ")
            .appendField("X")
            .appendField(new Blockly.FieldNumber(0, -getLength(), getLength()), "X")
            .appendField("cm")
            .appendField("Y")
            .appendField(new Blockly.FieldNumber(0, -getWidth(), getWidth()), "Y")
            .appendField("cm")
            .appendField("Z")
            .appendField(new Blockly.FieldNumber(80, 80, getHeight()), "Z")
            .appendField("cm");
        this.setInputsInline(true);
        this.setPreviousStatement(true, "ReachAction");
        this.setNextStatement(true, "ReachAction");
        this.setColour(250);
        this.setTooltip('');
    }
};
Blockly.Python['Goertek_ReachPosition'] = function(block) {
    var px = block.getFieldValue('X');
    var py = block.getFieldValue('Y');
    var pz = block.getFieldValue('Z');
    // TODO: Assemble Python into code variable.
    var code = 'Reach(f1,' + px + ',' + py + ',' + pz + ')' + '\n';
    // var code = '';
    return code;
};
Blockly.Blocks['Goertek_ReachPositionDelta'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("Reach直线移动 ")
            .appendField("X")
            .appendField(new Blockly.FieldNumber(0, -getLength(), getLength()), "X")
            .appendField("cm")
            .appendField("Y")
            .appendField(new Blockly.FieldNumber(0, -getWidth(), getWidth()), "Y")
            .appendField("cm")
            .appendField("Z")
            .appendField(new Blockly.FieldNumber(0, -getHeight(), getHeight()), "Z")
            .appendField("cm");
        this.setInputsInline(true);
        this.setPreviousStatement(true, ["ReachAction"]);
        this.setNextStatement(true, ["ReachAction"]);
        this.setColour(250);
        this.setTooltip('');
    }
};
Blockly.Python['Goertek_ReachPositionDelta'] = function(block) {
    var px = block.getFieldValue('X');
    var py = block.getFieldValue('Y');
    var pz = block.getFieldValue('Z');
    // TODO: Assemble Python into code variable.
    var code = 'ReachDelta(f1,' + px + ',' + py + ',' + pz + ')' + '\n';
    // var code = '';
    return code;
};
Blockly.Blocks['Goertek_ReachToPoint'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("Reach直线移至 ")
            .appendField("标定点")
            .appendField(new Blockly.FieldTextInput("a"), "point");
        this.setInputsInline(true);
        this.setPreviousStatement(true, "ReachAction");
        this.setNextStatement(true, "ReachAction");
        this.setColour(250);
        this.setTooltip('');
    }
};
Blockly.Python['Goertek_ReachToPoint'] = function(block) {
    var point = block.getFieldValue('point');
    var code = 'ReachMarker(f1,\'' + point + '\')' + '\n';
    return code;
};

Blockly.Blocks['Goertek_ReachAngle'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("Reach转向")
            .appendField(new Blockly.FieldDropdown([
                ["左", "l"],
                ["右", "r"]
            ]), "turnDirection")
            .appendField(new Blockly.FieldNumber(0, 0, 359), "angle")
            .appendField("°");
        this.setPreviousStatement(true, "ReachAction");
        this.setNextStatement(true, "ReachAction");
        this.setColour(160);
        this.setTooltip('');
    }
};
Blockly.Python['Goertek_ReachAngle'] = function(block) {
    var turnDirection = block.getFieldValue('turnDirection');
    var angle = block.getFieldValue('angle');
    // TODO: Assemble Python into code variable.
    var code = 'ReachYaw(f1,\'' + turnDirection + '\',' + angle + ')' + '\n';
    return code;
};
Blockly.Blocks['Goertek_ReachAngleDelta'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("Reach转动")
            .appendField(new Blockly.FieldDropdown([
                ["左", "l"],
                ["右", "r"]
            ]), "turnDirection")
            .appendField(new Blockly.FieldNumber(0, 0, 360), "angle")
            .appendField("°");
        this.setPreviousStatement(true, "ReachAction");
        this.setNextStatement(true, "ReachAction");
        this.setColour(160);
        this.setTooltip('');
    }
};
Blockly.Python['Goertek_ReachAngleDelta'] = function(block) {
    var turnDirection = block.getFieldValue('turnDirection');
    var angle = block.getFieldValue('angle');
    // TODO: Assemble Python into code variable.
    var code = 'ReachDeltaYaw(f1,\'' + turnDirection + '\',' + angle + ')' + '\n';
    return code;
};

// ============================进阶动作===================================
Blockly.Blocks['Goertek_HighSpeedTranslate'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("急速平移 沿")
            .appendField(new Blockly.FieldDropdown([
                ["X", "x"],
                ["-X", "-x"],
                ["Y", "y"],
                ["-Y", "-y"],
            ]), "axis")
            .appendField("轴方向急速平移")
            .appendField(new Blockly.FieldNumber(0, 0, 30), "d")
            .appendField("cm");
        this.setInputsInline(true);
        this.setPreviousStatement(true, ["action", "notReachAction", "ReachAction"]);
        this.setNextStatement(true, ["action", "notReachAction", "ReachAction"]);
        this.setColour(250);
        this.setTooltip('');
    }
};
Blockly.Python['Goertek_HighSpeedTranslate'] = function(block) {
    var axis = block.getFieldValue('axis');
    var d = block.getFieldValue('d');
    var code = 'Nod(f1,\'' + axis + '\',' + d + ')' + '\n';
    return code;
};

Blockly.Blocks['Goertek_TurnTranslate'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("转向平移 沿")
            .appendField(new Blockly.FieldDropdown([
                ["X", "x"],
                ["-X", "-x"],
                ["Y", "y"],
                ["-Y", "-y"],
                ["Z", "z"],
                ["-Z", "-z"],
            ]), "axis")
            .appendField("轴方向平移")
            .appendField(new Blockly.FieldNumber(0, 0, 100), "d")
            .appendField("cm")
            .appendField("同时")
            .appendField(new Blockly.FieldDropdown([
                ["顺时针", "1"],
                ["逆时针", "0"],
            ]), "clockwise")
            .appendField("转动")
            .appendField(new Blockly.FieldNumber(0, 0, 720), "θ")
            .appendField("°");
        this.setInputsInline(true);
        this.setPreviousStatement(true, ["action", "notReachAction", "ReachAction"]);
        this.setNextStatement(true, ["action", "notReachAction", "ReachAction"]);
        this.setColour(250);
        this.setTooltip('');
    }
};
Blockly.Python['Goertek_TurnTranslate'] = function(block) {
    var axis = block.getFieldValue('axis');
    var d = block.getFieldValue('d');
    var clockwise = block.getFieldValue('clockwise');
    var θ = block.getFieldValue('θ');
    var code = 'MovewHeading(f1,\'' + axis + '\',' + d + ',' + clockwise + ',' + θ + ')' + '\n';
    return code;
};

Blockly.Blocks['Goertek_SpiralTranslate'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("螺旋平移 沿以标定点")
            .appendField(new Blockly.FieldDropdown([
                ["X", "x"],
                ["-X", "-x"],
                ["Y", "y"],
                ["-Y", "-y"],
                ["Z", "z"],
                ["-Z", "-z"],
            ]), "axis")
            .appendField("轴方向 以标定点")
            .appendField(new Blockly.FieldTextInput("a"), "point")
            .appendField("为圆心")
        this.appendDummyInput()   
        .appendField("半径")
          .appendField(new Blockly.FieldNumber(50, 50, 50), "raduis")
            .appendField("cm 角频率")
            .appendField(new Blockly.FieldDropdown([
                ["90", "90"]
            ]), "ω")
            .appendField(new Blockly.FieldDropdown([
                ["顺时针", "1"],
                ["逆时针", "0"],
            ]), "clockwise")
            .appendField("转")
            .appendField(new Blockly.FieldTextInput("0"), "n")
            .appendField("圈 平移")
            .appendField(new Blockly.FieldNumber(0, 0, Math.min(getLength(), getWidth(), getHeight())), "d")
            .appendField("cm");
        this.setPreviousStatement(true, ["action", "notReachAction", "ReachAction"]);
        this.setNextStatement(true, ["action", "notReachAction", "ReachAction"]);
        this.setColour(250);
        this.setTooltip('');
    }
};
Blockly.Python['Goertek_SpiralTranslate'] = function(block) {
    var point = block.getFieldValue('point');
    var raduis = block.getFieldValue('raduis');
    var axis = block.getFieldValue('axis');
    var clockwise = block.getFieldValue('clockwise');
    var omega = block.getFieldValue('ω');
    var n = block.getFieldValue('n');
    var d = block.getFieldValue('d');
    var code = 'CylindricalSpiral(f1,\'' + axis + '\',\'' + point + '\','+ clockwise + ','+omega+ ','+raduis+ ',' + d + ','+ n + ')' + '\n';
    return code;
};

Blockly.Blocks['Goertek_SimpleHarmonicMotio'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("简谐运动 沿")
            .appendField(new Blockly.FieldDropdown([
                ["X", "x"],
                ["-X", "-x"],
                ["Y", "y"],
                ["-Y", "-y"],
                ["Z", "z"],
                ["-Z", "-z"],
            ]), "axis")
            .appendField("轴方向以振幅")
            .appendField(new Blockly.FieldNumber(50, 50, 50), "amplitude")
            .appendField("角频率")
            .appendField(new Blockly.FieldDropdown([
                ["90", "90"]
            ]), "ω")
            .appendField("初始相位")
            .appendField(new Blockly.FieldDropdown([
                ["0", "0"],
                ["90", "90"],
                ["180", "180"],
                ["270", "270"],
            ]), "φ")
            .appendField("重复")
            .appendField(new Blockly.FieldNumber(1, 1, 10), "n")
            .appendField("次")
        this.setInputsInline(true);
        this.setPreviousStatement(true, ["action", "notReachAction", "ReachAction"]);
        this.setNextStatement(true, ["action", "notReachAction", "ReachAction"]);
        this.setColour(250);
        this.setTooltip('');
    }
};
Blockly.Python['Goertek_SimpleHarmonicMotio'] = function(block) {
    var axis = block.getFieldValue('axis');
    var a = block.getFieldValue('amplitude');
    var ω = block.getFieldValue('ω');
    var φ = block.getFieldValue('φ');
    var n = block.getFieldValue('n');
    var code = 'SimpleHarmonic2(f1,\'' + axis + '\',' + a + ',' + ω + ',' + φ + ',' + n + ')' + '\n';
    return code;
};

Blockly.Blocks['Goertek_RollInAir'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("空翻运动 沿")
            .appendField(new Blockly.FieldDropdown([
                ["X", "x"],
                ["-X", "-x"],
                ["Y", "y"],
                ["-Y", "-y"],
            ]), "axis")
            .appendField("轴方向翻滚")
        this.setInputsInline(true);
        this.setPreviousStatement(true, ["action", "notReachAction", "ReachAction"]);
        this.setNextStatement(true, ["action", "notReachAction", "ReachAction"]);
        this.setColour(250);
        this.setTooltip('');
    }
};
Blockly.Python['Goertek_RollInAir'] = function(block) {
    var axis = block.getFieldValue('axis');
    var code = 'Flip(f1,\'' + axis + '\')\n';
    return code;
};

//======================废弃================================
/*Blockly.Blocks['Goertek_Forward'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("前进 ")
            .appendField("flight")
            .appendField(new Blockly.FieldTextInput("f1"), "plane")
            .appendField("Dx(cm)")
            .appendField(new Blockly.FieldTextInput("0"), "advance");
        this.setInputsInline(true);
        this.setPreviousStatement(true,["action", "notReachAction", "ReachAction"]);
        this.setNextStatement(true,["action", "notReachAction", "ReachAction"]);
        this.setColour(250);
        this.setTooltip('');
        this.setHelpUrl('http://www.example.com/');
    }
};
Blockly.Python['Goertek_Forward'] = function(block) {
    var getair = block.getFieldValue('plane');
    var text_advance = block.getFieldValue('advance');
    // TODO: Assemble Python into code variable.
    var code = 'Forward(' + getair + ',' + text_advance + ')' + '\n';
    return code;
};

Blockly.Blocks['Goertek_Backward'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("后退 ")
            .appendField("flight")
            .appendField(new Blockly.FieldTextInput("f1"), "plane")
            .appendField("Dx(cm)")
            .appendField(new Blockly.FieldTextInput("0"), "retreat");
        this.setInputsInline(true);
        this.setPreviousStatement(true,["action", "notReachAction", "ReachAction"]);
        this.setNextStatement(true,["action", "notReachAction", "ReachAction"]);
        this.setColour(250);
        this.setTooltip('');
        this.setHelpUrl('http://www.example.com/');
    }
};
Blockly.Python['Goertek_Backward'] = function(block) {
    var getair = block.getFieldValue('plane');
    var text_retreat = block.getFieldValue('retreat');
    // TODO: Assemble Python into code variable.
    var code = 'Backward(' + getair + ',' + text_retreat + ')' + '\n';
    return code;
};

Blockly.Blocks['Goertek_TurnLeft'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("向左 ")
            .appendField("flight")
            .appendField(new Blockly.FieldTextInput("f1"), "plane")
            .appendField("Dy(cm)")
            .appendField(new Blockly.FieldTextInput("0"), "turnleft");
        this.setInputsInline(true);
        this.setPreviousStatement(true,["action", "notReachAction", "ReachAction"]);
        this.setNextStatement(true,["action", "notReachAction", "ReachAction"]);
        this.setColour(250);
        this.setTooltip('');
        this.setHelpUrl('http://www.example.com/');
    }
};
Blockly.Python['Goertek_TurnLeft'] = function(block) {
    var getair = block.getFieldValue('plane');
    var text_turnleft = block.getFieldValue('turnleft');
    // TODO: Assemble Python into code variable.
    var code = 'Left(' + getair + ',' + text_turnleft + ')' + '\n';
    return code;
};

Blockly.Blocks['Goertek_TurnRight'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("向右 ")
            .appendField("flight")
            .appendField(new Blockly.FieldTextInput("f1"), "plane")
            .appendField("Dy(cm)")
            .appendField(new Blockly.FieldTextInput("0"), "turnright");
        this.setInputsInline(true);
        this.setPreviousStatement(true,["action", "notReachAction", "ReachAction"]);
        this.setNextStatement(true,["action", "notReachAction", "ReachAction"]);
        this.setColour(250);
        this.setTooltip('');
        this.setHelpUrl('http://www.example.com/');
    }
};
Blockly.Python['Goertek_TurnRight'] = function(block) {
    var getair = block.getFieldValue('plane');
    var text_turnright = block.getFieldValue('turnright');
    // TODO: Assemble Python into code variable.
    var code = 'Right(' + getair + ',' + text_turnright + ')' + '\n';
    return code;
};

Blockly.Blocks['Goertek_LYaw'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("左旋 ")
            .appendField("flight")
            .appendField(new Blockly.FieldTextInput("f1"), "plane")
            .appendField("Angle")
            .appendField(new Blockly.FieldTextInput("0"), "angle");
        this.setInputsInline(true);
        this.setPreviousStatement(true,["action", "notReachAction", "ReachAction"]);
        this.setNextStatement(true,["action", "notReachAction", "ReachAction"]);
        this.setColour(250);
        this.setTooltip('');
        this.setHelpUrl('http://www.example.com/');
    }
};
Blockly.Python['Goertek_LYaw'] = function(block) {
    var getair = block.getFieldValue('plane');
    var text_goup = block.getFieldValue('angle');
    // TODO: Assemble Python into code variable.
    var code = 'Yaw(' + getair + ',' + text_goup + ')' + '\n';
    return code;
};

Blockly.Blocks['Goertek_RYaw'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("右旋 ")
            .appendField("flight")
            .appendField(new Blockly.FieldTextInput("f1"), "plane")
            .appendField("Angle")
            .appendField(new Blockly.FieldTextInput("0"), "angle");
        this.setInputsInline(true);
        this.setPreviousStatement(true,["action", "notReachAction", "ReachAction"]);
        this.setNextStatement(true,["action", "notReachAction", "ReachAction"]);
        this.setColour(250);
        this.setTooltip('');
        this.setHelpUrl('http://www.example.com/');
    }
};
Blockly.Python['Goertek_RYaw'] = function(block) {
    var getair = block.getFieldValue('plane');
    var text_goup = block.getFieldValue('angle');
    // TODO: Assemble Python into code variable.
    var code = 'Yaw(' + getair + ',' + text_goup + ')' + '\n';
    return code;
};

Blockly.Blocks['Goertek_GoUp'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("上升 ")
            .appendField("flight")
            .appendField(new Blockly.FieldTextInput("f1"), "plane")
            .appendField("Dz(cm)")
            .appendField(new Blockly.FieldTextInput("0"), "goup");
        this.setInputsInline(true);
        this.setPreviousStatement(true,["action", "notReachAction", "ReachAction"]);
        this.setNextStatement(true,["action", "notReachAction", "ReachAction"]);
        this.setColour(250);
        this.setTooltip('');
        this.setHelpUrl('http://www.example.com/');
    }
};
Blockly.Python['Goertek_GoUp'] = function(block) {
    var getair = block.getFieldValue('plane');
    var text_goup = block.getFieldValue('goup');
    // TODO: Assemble Python into code variable.
    var code = 'Up(' + getair + ',' + text_goup + ')' + '\n';
    return code;
};

Blockly.Blocks['Goertek_Descend'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("下降 ")
            .appendField("flight")
            .appendField(new Blockly.FieldTextInput("f1"), "plane")
            .appendField("Dz(cm)")
            .appendField(new Blockly.FieldTextInput("0"), "descend");
        this.setInputsInline(true);
        this.setPreviousStatement(true,["action", "notReachAction", "ReachAction"]);
        this.setNextStatement(true,["action", "notReachAction", "ReachAction"]);
        this.setColour(250);
        this.setTooltip('');
        this.setHelpUrl('http://www.example.com/');
    }
};
Blockly.Python['Goertek_Descend'] = function(block) {
    var getair = block.getFieldValue('plane');
    var text_descend = block.getFieldValue('descend');
    // TODO: Assemble Python into code variable.
    var code = 'Down(' + getair + ',' + text_descend + ')' + '\n';
    return code;
};

Blockly.Blocks['Goertek_RollOrigin'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("原地翻滚 ")
            .appendField("flight")
            .appendField(new Blockly.FieldTextInput("f1"), "plane")
            .appendField("orientation")
            .appendField(new Blockly.FieldTextInput("0"), "angle");
        this.setInputsInline(true);
        this.setPreviousStatement(true,["action", "notReachAction", "ReachAction"]);
        this.setNextStatement(true,["action", "notReachAction", "ReachAction"]);
        this.setColour(250);
        this.setTooltip('');
        this.setHelpUrl('http://www.example.com/');
    }
};
Blockly.Python['Goertek_RollOrigin'] = function(block) {
    var getair = block.getFieldValue('plane');
    var text_goup = block.getFieldValue('angle');
    var code = 'Flip(' + getair + ',' + text_goup + ')' + '\n';
    return code;
};

Blockly.Blocks['Goertek_PitchOrigin'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("原地俯仰 ")
            .appendField("flight")
            .appendField(new Blockly.FieldTextInput("f1"), "plane")
            .appendField("orientation")
            .appendField(new Blockly.FieldTextInput("0"), "angle");
        this.setInputsInline(true);
        this.setPreviousStatement(true,["action", "notReachAction", "ReachAction"]);
        this.setNextStatement(true,["action", "notReachAction", "ReachAction"]);
        this.setColour(250);
        this.setTooltip('');
        this.setHelpUrl('http://www.example.com/');
    }
};
Blockly.Python['Goertek_PitchOrigin'] = function(block) {
    var getair = block.getFieldValue('plane');
    var text_goup = block.getFieldValue('angle');
    var code = 'Flip(' + getair + ',' + text_goup + ')' + '\n';
    return code;
};

Blockly.Blocks['Goertek_LYaw90'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("左旋90° ")
            .appendField("flight")
            .appendField(new Blockly.FieldTextInput("f1"), "plane");
        this.setInputsInline(true);
        this.setPreviousStatement(true,["action", "notReachAction", "ReachAction"]);
        this.setNextStatement(true,["action", "notReachAction", "ReachAction"]);
        this.setColour(250);
        this.setTooltip('');
        this.setHelpUrl('http://www.example.com/');
    }
};
Blockly.Python['Goertek_LYaw90'] = function(block) {
    var getair = block.getFieldValue('plane');
    var code = 'Yaw(' + getair + ',' + '9000' + ')' + '\n';
    return code;
};

Blockly.Blocks['Goertek_RYaw90'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("右旋90° ")
            .appendField("flight")
            .appendField(new Blockly.FieldTextInput("f1"), "plane");
        this.setInputsInline(true);
        this.setPreviousStatement(true,["action", "notReachAction", "ReachAction"]);
        this.setNextStatement(true,["action", "notReachAction", "ReachAction"]);
        this.setColour(250);
        this.setTooltip('');
        this.setHelpUrl('http://www.example.com/');
    }
};
Blockly.Python['Goertek_RYaw90'] = function(block) {
    var getair = block.getFieldValue('plane');
    var code = 'Yaw(' + getair + ',' + '-9000' + ')' + '\n';
    return code;
};

Blockly.Blocks['Goertek_Hover'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("悬停 ")
            .appendField("flight")
            .appendField(new Blockly.FieldTextInput("f1"), "land");
        this.setPreviousStatement(true,["action", "notReachAction", "ReachAction"]);
        this.setNextStatement(true,["action", "notReachAction", "ReachAction"]);
        this.setColour(250);
        this.setTooltip('');
        this.setHelpUrl('http://www.example.com/');
    }
};
Blockly.Python['Goertek_Hover'] = function(block) {
    // TODO: Assemble Python into code variable.
    var getvalue = block.getFieldValue('land');
    var code = 'Hover(' + getvalue + ')' + '\n';
    return code; //返回的函数
};




Blockly.Blocks['Goertek_DeviceCtrl'] = {
    init: function() {
        this.appendDummyInput()
            .appendField("控制设备 ")
            .appendField("deviceID")
            .appendField(new Blockly.FieldTextInput("deviceID"), "plane")
            .appendField("cmd1")
            .appendField(new Blockly.FieldTextInput("cmd1"), "cmd1")
            .appendField("cmd2")
            .appendField(new Blockly.FieldTextInput("cmd2"), "cmd2");
        this.setInputsInline(true);
        this.setPreviousStatement(true, null);
        this.setNextStatement(true, null);
        this.setColour(250);
        this.setTooltip('');
        this.setHelpUrl('http://www.example.com/');
    }
};
Blockly.Python['Goertek_DeviceCtrl'] = function(block) {
    var getair = block.getFieldValue('plane');
    var text_cmd1 = block.getFieldValue('cmd1');
    var text_cmd2 = block.getFieldValue('cmd2');
    var code = 'Device_control(' + getair + ',' + text_cmd1 + ',' + text_cmd2 + ')' + '\n';
    return code;
};*/